//package com.example.togethermove.utils.wechat;
//
//import android.content.Context;
//import android.graphics.Bitmap;
//import android.graphics.BitmapFactory;
//import android.os.Build;
//import android.util.Log;
//
//import com.example.togethermove.config.Config;
//import com.example.togethermove.config.HttpConfig;
//import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
//import com.tencent.mm.opensdk.modelmsg.WXImageObject;
//import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
//import com.tencent.mm.opensdk.modelmsg.WXTextObject;
//import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
//import com.tencent.mm.opensdk.openapi.IWXAPI;
//import com.tencent.mm.opensdk.openapi.WXAPIFactory;
//
//import java.util.logging.Logger;
//
//
///**
// * @author csl
// * @data
// */
//public class ShareUtil {
//    public static String WeichatSmall = "";
//    private static final int THUMB_SIZE = 80;
//
//    public static void wechatShareImgFriend(Context context, Bitmap bmp) {
//        wechatShareImg(context, bmp, SendMessageToWX.Req.WXSceneSession);
////        MemberShare.addMemberShare();
//    }
//
//    public static void wechatShareImgMoment(Context context, Bitmap bmp) {
//        wechatShareImg(context, bmp, SendMessageToWX.Req.WXSceneTimeline);
////        MemberShare.addMemberShare();
//    }
//
//    public static void wechatShareTxtFriend(Context context, String txt) {
//        wechatShareText(context, txt, SendMessageToWX.Req.WXSceneSession);
//    }
//
//    public static void wechatShareTxtMoment(Context context, String txt) {
//        wechatShareText(context, txt, SendMessageToWX.Req.WXSceneTimeline);
//    }
//
//    public static void wechatShareWebFriend(Context context, String pageUrl, String title, String description, int bmpResource) {
//        wechatShareWeb(context, pageUrl, title, description, bmpResource, SendMessageToWX.Req.WXSceneSession);
////        MemberShare.addMemberShare();
//    }
//
//    public static void wechatShareWebMoment(Context context, String pageUrl, String title, String description, int bmpResource) {
//        wechatShareWeb(context, pageUrl, title, description, bmpResource, SendMessageToWX.Req.WXSceneTimeline);
////        MemberShare.addMemberShare();
//    }
//    public static void wechatShareWebFriend2(Context context, String pageUrl, String title, String description, Bitmap bmpResource) {
//        wechatShareWeb2(context, pageUrl, title, description, bmpResource, SendMessageToWX.Req.WXSceneSession);
//    }
//
//    public static void wechatShareWebMoment2(Context context, String pageUrl, String title, String description, Bitmap bmpResource) {
//        wechatShareWeb2(context, pageUrl, title, description, bmpResource, SendMessageToWX.Req.WXSceneTimeline);
//    }
////    /**
////     *
////     * @param context
////     * @param bmpResource
////     * @param title
////     * @param description  分享到小程序
////     * @param miniProgramData
////     */
////    public static void wechatShareMiniProgram(Context context, int bmpResource, String title, String description, MiniProgramData miniProgramData) {
////        IWXAPI api= WXAPIFactory.createWXAPI(context, Config.wechatId, false);
////        WXMiniProgramObject miniProgramObj = new WXMiniProgramObject();
////        miniProgramObj.webpageUrl = ConfigUtil.getShareUrl(); // 兼容低版本的网页链接
////        miniProgramObj.miniprogramType = WXMiniProgramObject.MINIPTOGRAM_TYPE_RELEASE;// 正式版:0，测试版:1，体验版:2
////        miniProgramObj.userName = "gh_5f3d55a702ea";     // 小程序原始id
////        miniProgramObj.path = "/"+ CalulateActivity.WeichatSmall + miniProgramData.createPathData();            //小程序页面路径
//////        miniProgramObj.path = "/pages/counter/main" + miniProgramData.createPathData();            //小程序页面路径
////        WXMediaMessage msg = new WXMediaMessage(miniProgramObj);
////        msg.title = title;                    // 小程序消息title
////        msg.description = description;               // 小程序消息desc
////        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), bmpResource);
////        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, 252, 252 * 4 / 5, true);
////        bmp.recycle();
////        msg.thumbData = WechatUtil.bmpToByteArray(thumbBmp, true);
////        SendMessageToWX.Req req = new SendMessageToWX.Req();
////        req.transaction = buildTransaction("miniProgram");
////        req.message = msg;
////        req.scene = SendMessageToWX.Req.WXSceneSession;  // 目前只支持会话
////        api.sendReq(req);
////    }
//
//    private static void wechatShareImg(Context context, Bitmap bmp, int targetScene) {
//        IWXAPI api = WXAPIFactory.createWXAPI(context, Config.wechatId, false);
//        WXMediaMessage msg = new WXMediaMessage();
//        if (getBitmapSize(bmp) < 1024 * 1024) {
//            Logger.getLogger("wechatShareImg：  " + "小于1024*1024");
//
//            WXImageObject imgObj = new WXImageObject(bmp);
//            msg.mediaObject = imgObj;
//        } else {
//            Logger.getLogger("wechatShareImg： " + "大于1024*1024");
//            WXImageObject imgObj = new WXImageObject();
//            imgObj.setImagePath(WechatUtil.createWeShareFile(context, bmp));
//            msg.mediaObject = imgObj;
//        }
//        boolean registerApp = api.registerApp(Config.wechatId);
//        Log.e("registerApp", "registerApp: " + registerApp);
//
//
//        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
////        bmp.recycle();
//        msg.thumbData = WechatUtil.bmpToByteArray(thumbBmp, true);
//
//        SendMessageToWX.Req req = new SendMessageToWX.Req();
//        req.transaction = buildTransaction("img");
//        req.message = msg;
//        req.scene = targetScene;
//        boolean b = api.sendReq(req);
//        Logger.getLogger("sendBitmap", String.valueOf(b));
//
//    }
//
//    private static int getBitmapSize(Bitmap bitmap) {
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            return bitmap.getAllocationByteCount();
//        } else {
//            return bitmap.getByteCount();
//        }
//    }
//
//    private static void wechatShareText(Context context, String txt, int targetScene) {
//        IWXAPI api = WXAPIFactory.createWXAPI(context, Config.wechatId, false);
//        WXTextObject textObj = new WXTextObject();
//        textObj.text = txt;
//        WXMediaMessage msg = new WXMediaMessage();
//        msg.mediaObject = textObj;
//        msg.description = txt;
//        SendMessageToWX.Req req = new SendMessageToWX.Req();
//        req.transaction = buildTransaction("text");
//        req.message = msg;
//        req.scene = targetScene;
//        api.sendReq(req);
//    }
//
//    private static void wechatShareWeb(Context context, String pageUrl, String title, String description, int bmpResource, int mTargetScene) {
//        IWXAPI api = WXAPIFactory.createWXAPI(context, Config.wechatId, false);
//        WXWebpageObject webPage = new WXWebpageObject();
//        webPage.webpageUrl = HttpConfig.h5Url()+ pageUrl;
//        WXMediaMessage msg = new WXMediaMessage(webPage);
//        msg.title = title;
//        msg.description = description;
//        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), bmpResource);
//        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
//        bmp.recycle();
//        msg.thumbData = WechatUtil.bmpToByteArray(thumbBmp, true);
//
//        SendMessageToWX.Req req = new SendMessageToWX.Req();
//        req.transaction = buildTransaction("webpage");
//        req.message = msg;
//        req.scene = mTargetScene;
//        api.sendReq(req);
//    }
//
//    private static void wechatShareWeb2(final Context context, String pageUrl, String title, String description,  Bitmap bmp, final int mTargetScene) {
//        final IWXAPI api= WXAPIFactory.createWXAPI(context, Config.wechatId, false);
//        WXWebpageObject webPage = new WXWebpageObject();
//        webPage.webpageUrl = HttpConfig.h5Url()+ pageUrl;
//        final WXMediaMessage msg = new WXMediaMessage(webPage);
//        msg.title = title;
//        msg.description = description;
//
//        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
//        bmp.recycle();
//        msg.thumbData = WechatUtil.bmpToByteArray(thumbBmp, true);
//
//        SendMessageToWX.Req req = new SendMessageToWX.Req();
//        req.transaction = buildTransaction("webpage");
//        req.message = msg;
//        req.scene = mTargetScene;
//        api.sendReq(req);
//
//
//    }
//    private static String buildTransaction(final String type) {
//        return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
//    }
//
////    public static List<String> getShare(List<Params> bean) {
////        List<String> mlist = new ArrayList<>();
////        if (bean != null && bean.size() > 0) {
////            for (int i = 0; i < bean.size(); i++) {
////                if (bean.get(i).getPKey().equals("homepageShareTitle")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("homepageShareUrl")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("homepageShareDesc")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("videShareTitle")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("videoShareUrl")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("videoShareDesc")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////
////                if (bean.get(i).getPKey().equals("inviteViewerShareTitle")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("inviteViewerShareUrl")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("inviteViewerShareDesc")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("inviteCreatorShareTitle")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("inviteCreatorShareUrl")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////                if (bean.get(i).getPKey().equals("inviteCreatorShareDesc")) {
////                    mlist.add(bean.get(i).getPVal());
////                }
////
////
////            }
////        } else {
////            return null;
////        }
////        return mlist;
////    }
//}
